package com.kgc.controller;

import com.kgc.domain.Account;
import com.kgc.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * web控制
 */
@Controller
@RequestMapping("account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @RequestMapping("findAll")
    public String findAll(Model model) throws Exception {
        List<Account> list = accountService.findAll();
       model.addAttribute("list",list);
        System.out.println("表现层---查询所有的账号信息");
        return "list";
    }
    @RequestMapping("save")
    public void save(Account account, HttpServletRequest request, HttpServletResponse response) throws Exception {
      accountService.saveAccount(account);
      response.sendRedirect(request.getContextPath()+"/account/findAll");
        return;
    }

}
